package com.gftBrazil.BankSystem.view;

import com.gftBrazil.BankSystem.bean.ClienteBean;
import com.gftBrazil.BankSystem.bean.ClienteFisicoBean;
import com.gftBrazil.BankSystem.bean.ClienteJuridicoBean;
import com.gftBrazil.BankSystem.bean.enums.EstadoCliente;
import com.gftBrazil.BankSystem.bean.enums.Permissao;
import com.gftBrazil.BankSystem.bean.enums.UnidadeFederativa;
import com.gftBrazil.BankSystem.business.ClienteBusiness;
import com.gftBrazil.BankSystem.controller.cliente.ClienteController;
import com.gftBrazil.BankSystem.controller.cliente.ClienteFisicoController;
import com.gftBrazil.BankSystem.controller.cliente.ClienteJuridicoController;
import com.gftBrazil.BankSystem.exceptions.AcessoNegadoException;
import com.gftBrazil.BankSystem.exceptions.RegraNegocioException;
import com.gftBrazil.BankSystem.sistema.Acessivel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatterFactory;

/**
 *
 * @author JRSS
 */
public class ClienteView extends javax.swing.JInternalFrame implements Acessivel {

    private List<JTextField> componentes;

    /**
     * Creates new form ClienteView
     */
    public ClienteView() {
        initComponents();
        initListeners();
    }

    private void addComponentesObrigatorios(boolean novoCliente) {
        componentes = new ArrayList<>();
        if (novoCliente) {
            this.componentes.add(tNome);
            this.componentes.add(tCidade);
            this.componentes.add(tCpfCnpj);
        } else {
            this.componentes.add(tCodigoCliente);
        }
    }

    public List<JTextField> getComponentes() {
        return componentes;
    }

    public void setMensagem(String message) {
        this.tMensagem.setText(message);
    }

    public ClienteView(boolean novoCliente) {
        this();
        if (novoCliente) {
            tCodigoCliente.setEnabled(false);
            bConsultarCliente.setEnabled(false);
        } else {
            tNome.setEnabled(false);
            tCidade.setEnabled(false);
            cbEstados.setEnabled(false);
            tCpfCnpj.setEnabled(false);
            bSalvar.setEnabled(false);
        }
        addComponentesObrigatorios(novoCliente);
        mostra();
    }

    public ClienteView(boolean novoCliente, ClienteBean cliente) {
        this(novoCliente);
        this.cliente = cliente;
        if (novoCliente) {
            tCodigoCliente.setEnabled(false);
            bConsultarCliente.setEnabled(false);
        } else {
            tNome.setEnabled(false);
            tCidade.setEnabled(false);
            cbEstados.setEnabled(false);
            tCpfCnpj.setEnabled(false);
            bSalvar.setEnabled(false);
        }
        preparaCampos(cliente);
        mostra();
    }

    private void initListeners() {
        this.tCodigoCliente.addKeyListener(trataTeclas);
        this.bConsultarCliente.addKeyListener(trataTeclas);
        this.tNome.addKeyListener(trataTeclas);
        this.tCidade.addKeyListener(trataTeclas);
        this.cbEstados.addKeyListener(trataTeclas);
        this.tCpfCnpj.addKeyListener(trataTeclas);
        this.bSalvar.addKeyListener(trataTeclas);

        this.bConsultarCliente.addActionListener(trataBotoes);
        this.bSalvar.addActionListener(trataBotoes);
        this.bCancelar.addActionListener(trataBotoes);
        this.bBloquear.addActionListener(trataBotoes);
        this.bReativar.addActionListener(trataBotoes);
        this.bMaisUm.addActionListener(trataBotoes);

        this.tNome.addFocusListener(trataFoco);
        this.tCidade.addFocusListener(trataFoco);
        this.tCpfCnpj.addFocusListener(trataFoco);

        this.cbEstados.addItemListener(trataItem);
    }

    private void preparaCampos(ClienteBean cliente) {
        String formato = null;
        javax.swing.text.MaskFormatter format;
        if (cliente instanceof ClienteFisicoBean) {
            formato = "###.###.###-##";
        } else if (cliente instanceof ClienteJuridicoBean) {
            formato = "##.###.###/####-##";
        }
        try {
            format = new javax.swing.text.MaskFormatter(formato);
            tCpfCnpj.setFormatterFactory(new DefaultFormatterFactory(format));
        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(getParent(),
                    "Erro ao atribuir mascara ao campo",
                    "Mascara CPF/CNPJ",
                    JOptionPane.ERROR_MESSAGE);
        }
        preparaEstado();
    }

    public void preparaEstado() {
        UnidadeFederativa[] es = UnidadeFederativa.values();
        DefaultComboBoxModel model = new DefaultComboBoxModel(es);
        cbEstados.setModel(model);
        if (cliente != null) {
            cliente.setUnidadeFederativa(UnidadeFederativa.SP);
        }
    }

    private void mostra() {
        if (cliente != null) {
            tCodigoCliente.setText(String.valueOf(cliente.getCodigoCliente()));
            tEstadoCliente.setText(cliente.getEstadoCliente().toString());
            tNome.setText(cliente.getNome());
            tCidade.setText(cliente.getCidade());
            UnidadeFederativa ue = cliente.getUnidadeFederativa();
            cbEstados.getModel().setSelectedItem(ue);
            if (cliente.getDocumento() != null) {
                tCpfCnpj.setFormatterFactory(new DefaultFormatterFactory(null));
            }
            tCpfCnpj.setText(cliente.getDocumento());
        }
    }

    private void consultar(int codigoCliente) {
        cliente = ClienteBusiness.getInstance().consultarClientePorCodigo(codigoCliente);
        if (cliente != null) {
            tMensagem.setText(" ");
        } else {
            limparDadosCliente();
            tMensagem.setText("Cliente nao encontrado!");
        }
        mostra();
    }

    private void salvar() throws AcessoNegadoException {
        ClienteController clienteController = null;
        if (cliente instanceof ClienteFisicoBean) {
            clienteController = new ClienteFisicoController(Permissao.CADASTRAR_CLIENTE);
        } else if (cliente instanceof ClienteJuridicoBean) {
            clienteController = new ClienteJuridicoController(Permissao.CADASTRAR_CLIENTE);
        }
        if (clienteController != null) {
            clienteController.setCliente(cliente);
            clienteController.salvar(this);
        }
        limparDadosCliente();
        mostra();
    }

    private void bloquear() throws AcessoNegadoException {
        try {
            verificaAlteracao(cliente.getEstadoCliente(), EstadoCliente.BLOQUEADO);
            ClienteController clienteController = null;
            if (cliente instanceof ClienteFisicoBean) {
                clienteController = new ClienteFisicoController(Permissao.ALTERAR_CLIENTE);
            } else if (cliente instanceof ClienteJuridicoBean) {
                clienteController = new ClienteJuridicoController(Permissao.ALTERAR_CLIENTE);
            }
            if (clienteController != null) {
                clienteController.setCliente(cliente);
                clienteController.bloquear(this);
            }
            mostra();
        } catch (RegraNegocioException ex) {
            tMensagem.setText(ex.getMessage());
        }
    }

    private void reativar() throws AcessoNegadoException {
        try {
            verificaAlteracao(cliente.getEstadoCliente(), EstadoCliente.ATIVO);
            ClienteController clienteController = null;
            if (cliente instanceof ClienteFisicoBean) {
                clienteController = new ClienteFisicoController(Permissao.ALTERAR_CLIENTE);
            } else if (cliente instanceof ClienteJuridicoBean) {
                clienteController = new ClienteJuridicoController(Permissao.ALTERAR_CLIENTE);
            }
            if (clienteController != null) {
                clienteController.setCliente(cliente);
                clienteController.reativar(this);
            }
            mostra();
        } catch (RegraNegocioException ex) {
            tMensagem.setText(ex.getMessage());
        }
    }

    private void cancelar() throws AcessoNegadoException {
        try {
            verificaAlteracao(cliente.getEstadoCliente(), EstadoCliente.CANCELADO);
            ClienteController clienteController = null;
            if (cliente instanceof ClienteFisicoBean) {
                clienteController = new ClienteFisicoController(Permissao.ALTERAR_CLIENTE);
            } else if (cliente instanceof ClienteJuridicoBean) {
                clienteController = new ClienteJuridicoController(Permissao.ALTERAR_CLIENTE);
            }
            if (clienteController != null) {
                clienteController.setCliente(cliente);
                clienteController.cancelar(this);
            }
            mostra();
        } catch (RegraNegocioException ex) {
            tMensagem.setText(ex.getMessage());
        }
    }

    public void limparDadosCliente() {
        if (cliente instanceof ClienteFisicoBean) {
            cliente = new ClienteFisicoBean();
            tCpfCnpj.setValue(null);
            preparaCampos(cliente);
        } else if (cliente instanceof ClienteJuridicoBean) {
            cliente = new ClienteJuridicoBean();
            tCpfCnpj.setValue(null);
            preparaCampos(cliente);
        } else if (cliente == null) {
            tNome.setText("");
            tCidade.setText("");
            cbEstados.getModel().setSelectedItem(UnidadeFederativa.SP);
        }
    }

    public void setCliente(ClienteBean cliente) {
        this.cliente = cliente;
    }

    public void verificaAlteracao(EstadoCliente atual, EstadoCliente futuro) throws RegraNegocioException {
        if ((cliente.getEstadoCliente() != EstadoCliente.ATIVO
                && (futuro == EstadoCliente.BLOQUEADO || futuro == EstadoCliente.CANCELADO))
                || cliente.getEstadoCliente() != EstadoCliente.BLOQUEADO
                && futuro == EstadoCliente.ATIVO) {
            throw new RegraNegocioException("Operacao invalida!");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        lCodigoCliente = new javax.swing.JLabel();
        tCodigoCliente = new javax.swing.JTextField();
        lEstadoCliente = new javax.swing.JLabel();
        tEstadoCliente = new javax.swing.JTextField();
        bConsultarCliente = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        lNome = new javax.swing.JLabel();
        tNome = new javax.swing.JTextField();
        lCidade = new javax.swing.JLabel();
        tCidade = new javax.swing.JTextField();
        lEstado = new javax.swing.JLabel();
        cbEstados = new javax.swing.JComboBox();
        lCpfCnpj = new javax.swing.JLabel();
        tCpfCnpj = new javax.swing.JFormattedTextField();
        pButtons = new javax.swing.JPanel();
        bSalvar = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();
        bReativar = new javax.swing.JButton();
        bBloquear = new javax.swing.JButton();
        bMaisUm = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        tMensagem = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Cliente View");
        setPreferredSize(new java.awt.Dimension(600, 200));
        getContentPane().setLayout(new java.awt.GridBagLayout());

        lCodigoCliente.setText("Codigo cliente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lCodigoCliente, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(tCodigoCliente, gridBagConstraints);

        lEstadoCliente.setText("Estado cliente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lEstadoCliente, gridBagConstraints);

        tEstadoCliente.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 2.0;
        getContentPane().add(tEstadoCliente, gridBagConstraints);

        bConsultarCliente.setText("Consultar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        getContentPane().add(bConsultarCliente, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(jSeparator1, gridBagConstraints);

        lNome.setText("Nome:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lNome, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(tNome, gridBagConstraints);

        lCidade.setText("Cidade:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lCidade, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 3.0;
        getContentPane().add(tCidade, gridBagConstraints);

        lEstado.setText("Estado:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        getContentPane().add(lEstado, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(cbEstados, gridBagConstraints);

        lCpfCnpj.setText("CPF/CNPJ:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(lCpfCnpj, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(tCpfCnpj, gridBagConstraints);

        pButtons.setLayout(new java.awt.GridBagLayout());

        bSalvar.setText("Salvar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        pButtons.add(bSalvar, gridBagConstraints);

        bCancelar.setText("Cancelar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        pButtons.add(bCancelar, gridBagConstraints);

        bReativar.setText("Reativar");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        pButtons.add(bReativar, gridBagConstraints);

        bBloquear.setText("Bloquear");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        pButtons.add(bBloquear, gridBagConstraints);

        bMaisUm.setText("Mais um");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        pButtons.add(bMaisUm, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(pButtons, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(jSeparator2, gridBagConstraints);

        tMensagem.setText(" ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(tMensagem, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public Permissao getPermissao() {
        return Permissao.CONSULTAR_CLIENTE;
    }

    private class TrataBotoes implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (ae.getSource() == bConsultarCliente) {
                try {
                    int codigoCliente = Integer.valueOf(tCodigoCliente.getText());
                    consultar(codigoCliente);
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(getParent(),
                            "Codigo de cliente invalido!",
                            "Erro",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else if (ae.getSource() == bSalvar) {
                try {
                    salvar();
                    mostra();
                    limparDadosCliente();
                } catch (AcessoNegadoException ex) {
                    JOptionPane.showMessageDialog(null,
                            "Acesso negado!",
                            "Acesso",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else if (ae.getSource() == bBloquear) {
                try {
                    bloquear();
                } catch (AcessoNegadoException ex) {
                    JOptionPane.showMessageDialog(null,
                            "Acesso negado!",
                            "Acesso",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else if (ae.getSource() == bReativar) {
                try {
                    reativar();
                } catch (AcessoNegadoException ex) {
                    JOptionPane.showMessageDialog(null,
                            "Acesso negado!",
                            "Acesso",
                            JOptionPane.WARNING_MESSAGE);
                }

            } else if (ae.getSource() == bCancelar) {
                try {
                    cancelar();
                } catch (AcessoNegadoException ex) {
                    JOptionPane.showMessageDialog(null,
                            "Acesso negado!",
                            "Acesso",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else if (ae.getSource() == bMaisUm) {
                limparDadosCliente();
                mostra();
                tNome.requestFocus();
                tMensagem.setText(" ");
            }
        }

    }

    private class TrataFoco implements FocusListener {

        @Override
        public void focusGained(FocusEvent fe) {

        }

        @Override
        public void focusLost(FocusEvent fe) {
            if (fe.getSource() == tNome) {
                String nome = tNome.getText();
                if (!nome.equals("")) {
                    cliente.setNome(nome);
                }
            } else if (fe.getSource() == tCidade) {
                String cidade = tCidade.getText();
                if (!cidade.equals("")) {
                    cliente.setCidade(cidade);
                }
            } else if (fe.getSource() == tCpfCnpj) {
                Object value = tCpfCnpj.getValue();
                if (value != null) {
                    cliente.setDocumento((String) value);
                }
            }
        }

    }

    private class TrataTeclas implements KeyListener {

        @Override
        public void keyTyped(KeyEvent ke) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_TAB || ke.getKeyCode() == KeyEvent.VK_ENTER) {
                if (ke.getSource() == tCodigoCliente) {
                    bConsultarCliente.requestFocus();
                } else if (ke.getSource() == bConsultarCliente && ke.getKeyCode() == KeyEvent.VK_ENTER) {
                    try {
                        int codigoCliente = Integer.valueOf(tCodigoCliente.getText());
                        consultar(codigoCliente);
                    } catch (NumberFormatException ex) {
                        JOptionPane.showMessageDialog(getParent(),
                                "Codigo de cliente invalido!",
                                "Erro",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } else if (ke.getSource() == tNome) {
                    tCidade.requestFocus();
                } else if (ke.getSource() == tCidade) {
                    cbEstados.requestFocus();
                } else if (ke.getSource() == cbEstados) {
                    tCpfCnpj.requestFocus();
                } else if (ke.getSource() == tCpfCnpj) {
                    bSalvar.requestFocus();
                } else if (ke.getSource() == bSalvar && ke.getKeyCode() == KeyEvent.VK_ENTER) {
                    try {
                        salvar();
                    } catch (AcessoNegadoException ex) {
                        JOptionPane.showMessageDialog(null,
                                "Acesso negado!",
                                "Acesso",
                                JOptionPane.WARNING_MESSAGE);
                    }
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent ke) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }

    private class TrataItem implements ItemListener {

        @Override
        public void itemStateChanged(ItemEvent ie) {
            if (ie.getSource() == cbEstados) {
                UnidadeFederativa ue = (UnidadeFederativa) cbEstados.getSelectedItem();
                cliente.setUnidadeFederativa(ue);
            }
        }
    }

    public ClienteBean getCliente() {
        return this.cliente;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBloquear;
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bConsultarCliente;
    private javax.swing.JButton bMaisUm;
    private javax.swing.JButton bReativar;
    private javax.swing.JButton bSalvar;
    private javax.swing.JComboBox cbEstados;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lCidade;
    private javax.swing.JLabel lCodigoCliente;
    private javax.swing.JLabel lCpfCnpj;
    private javax.swing.JLabel lEstado;
    private javax.swing.JLabel lEstadoCliente;
    private javax.swing.JLabel lNome;
    private javax.swing.JPanel pButtons;
    private javax.swing.JTextField tCidade;
    private javax.swing.JTextField tCodigoCliente;
    private javax.swing.JFormattedTextField tCpfCnpj;
    private javax.swing.JTextField tEstadoCliente;
    private javax.swing.JLabel tMensagem;
    private javax.swing.JTextField tNome;
    // End of variables declaration//GEN-END:variables
    private ClienteBean cliente;
    private final TrataBotoes trataBotoes = new TrataBotoes();
    private final TrataFoco trataFoco = new TrataFoco();
    private final TrataTeclas trataTeclas = new TrataTeclas();
    private final TrataItem trataItem = new TrataItem();
}
